package com.songminju.jsong_beanwithsql.crud;

/**
@todo
@description
@author songminju
@date 2017年12月3日
*/
public class CrudOption1 {
	
	public StringBuilder sql = new StringBuilder();
	private CrudType operation;
	private Object[] values = null;
	
	public CrudOption1(CrudType operation,String fields,String table) {
		this.operation = operation;
		switch (operation) {
		case SELECT:
			sql.append("SELECT ").append(fields).append(" FROM ").append(table).append(" WHERE ");
			break;
			
		case INSERT:
			int x = fields.split(",").length;
			sql.append("INSERT INTO ").append(table).append(" (").append(fields).append(")").append("values(");
			while(x-- > 0) {
				sql.append("?,");
			}
			sql.deleteCharAt(sql.length()-1);
			sql.append(")");
			break;
			
		case UPDATE:
			sql.append("SELECT ").append(fields).append(" FROM ").append(table).append(" WHERE 1=1");
			break;
		case DELETE:
			sql.append("SELECT ").append(fields).append(" FROM ").append(table).append(" WHERE 1=1");
			break;
		default:
			break;
		}
	}
	
	public CrudOption1 where(String filter) {
		sql.append(filter);
		return this;
	}
	
	public CrudOption1 tail(String tail) {
		sql.append(" ").append(tail);
		return this;
	}
	
	public void values(Object ...values) {
		this.values = values;
	}
	
	public Object[] getValues() {
		return this.values;
	}
	
}
